package org.onion.pattern.event.springboot.rocketmq.autoconfigure;


import org.apache.commons.lang3.ObjectUtils;
import org.onion.pattern.event.springboot.rocketmq.annotation.EnableRocketMQEvent;
import org.springframework.context.annotation.ImportSelector;
import org.springframework.core.annotation.MergedAnnotation;
import org.springframework.core.type.AnnotationMetadata;

public class RocketMQEventConfigurationSelector implements ImportSelector{

    @Override
    public String[] selectImports(AnnotationMetadata annotationMetadata) {
        MergedAnnotation<EnableRocketMQEvent> eventMergedAnnotation = annotationMetadata.getAnnotations().get(EnableRocketMQEvent.class);
        Boolean enableConsume = ObjectUtils.defaultIfNull(eventMergedAnnotation.getBoolean("enableConsume"), true);
        if(enableConsume){
            return new String[]{"org.onion.pattern.event.spring.autoconfigure.OnionPatternEventAutoConfigure",
            "org.onion.pattern.event.springboot.rocketmq.autoconfigure.RocketMQEventAutoConfigure",
            "org.onion.pattern.event.springboot.rocketmq.autoconfigure.RocketMQConsumeAutoConfiguration"};
        }
        return new String[]{"org.onion.pattern.event.spring.autoconfigure.OnionPatternEventAutoConfigure",
                "org.onion.pattern.event.springboot.rocketmq.autoconfigure.RocketMQEventAutoConfigure"};
    }
}
